<template>
	<view>
		<z-nav-bar
			:brand="brand"
			:rightIcon="rightIcon"
			@handleRightBtn="handleRightBtn"
			backState="2000"
		></z-nav-bar>
		<!-- 公共组件-每个页面必须引入 -->
		<!--<!--<public-module></public-module>-->
		<!-- banner -->
		<base-banner :banners="banners"/>
		<!-- 公告栏 -->
		<view class="notice-box">
			<uni-notice-bar showIcon single :text="noticeText" scrollable :speed="80"></uni-notice-bar>
		</view>
		<!-- 主菜单 -->
		<base-menu :menus="menus"/>
		<!-- 活动推广banner -->
		<base-banner :banners="smallBanners" small/>
		<!-- 面授课程 -->
		<base-menu :menus="smallMenus" small textAlignCenter title="面授课程" :row-height="88"/>
	</view>
</template>

<script>
import { mapState, mapMutations } from 'vuex';
import base from '@/config/baseUrl';
import baseBanner from '@/components/base-banner/base-banner.vue';
import baseMenu from '@/components/base-menu/base-menu.vue';
// #ifdef MP-WEIXIN
import { onLogin } from '@/config/login';
// import { getBanner,getPubBanner} from '@/config/api/home.js'
// #endif
export default {
	components: {
		baseBanner,
		baseMenu
	},
	data() {
		return {
			// logo 图片
			brand: require('@/static/logo.png'),
			rightIcon: require('@/static/icon/nav/search.png'),
			smallMenus: [],
		};
	},
	computed: {
		...mapState(['userInfo','noticeText','banners', 'smallBanners','menus'])
	},
	//第一次加载
	onLoad(e) {
		// #ifdef MP-WEIXIN
		this.onLoadBanner()
		// #endif
		
		this.$api.model.getModelList().then(res => {
			for(let i=0; i<(res.data.length>8?8:res.data.length); i++) {
				let data = res.data[i]
				let url = require('@/static/icon/menu/mianshou/1.png')
				if(data.url) {
					url =  base.baseUrl + data.url
				}
				this.smallMenus.push({judgeIsLogin: true,
									label: data.modelName, 
									id: data.modelId,
									icon: url,
									type: 'model',
									price: data.price,
									path: ''})
			}
			this.smallMenus.push({ judgeIsLogin: false,
								label: '全部班型', 
								id: '',
								icon: require('@/static/icon/menu/mianshou/4.png'), 
								type: 'model',
								price: 0,
								path: '/subpages/home/allModel' },)
		})
	},
	//页面显示
	onShow() {},
	//方法
	methods: {
		handleRightBtn() {
			// 右侧按钮点击事件
				// uni.navigateTo({
				// 	url: '/subpages/home/search'
				// });
			uni.showToast({
				icon: 'none',
				title: '暂未开放,敬请期待'
			});
		},
		onLoadBanner(){
			let params = {
				position: 0,
				attachType: 1
			}
			// getBanner(params).then((res)=>{
			// 	console.log('getbanner',res)
			// })	
			this.$api.home.getBanner(params).then((res)=>{
				console.log('getbanner',res)
			})
		}
	},
	//页面隐藏
	onHide() {},
	//页面卸载
	onUnload() {},
	//页面下来刷新
	onPullDownRefresh() {},
	//页面上拉触底
	onReachBottom() {},
	//用户点击分享
	onShareAppMessage(e) {
		return this.wxShare();
	}
};
</script>
<style lang="scss" scoped>
@import '@/style/mixin.scss';
.notice-box{
	width: 686upx;
	margin: 0 auto;
}
</style>
